﻿<common:LayoutAwarePage
    x:Name="pageRoot"
    x:Class="Manhua2.Pages.ComicDirectoryPage"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Manhua2.Pages"
    xmlns:common="using:Manhua2.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
    
    <Grid Style="{StaticResource LayoutRootStyle}">
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
            <TextBlock x:Name="pageTitle" Grid.Column="1" Text="{Binding ComicTitle}" Style="{StaticResource PageHeaderTextStyle}"/>
            <WebView Grid.Column="1" Margin="600,10,0,0" 
                             HorizontalAlignment="Left" 
                             VerticalAlignment="Top" 
                             Width="900" Height="120" Source="http://wowhy.sinaapp.com/metro.php"/>

        </Grid>

        <ScrollViewer Grid.Row="1" Style="{StaticResource HorizontalScrollViewerStyle}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="300" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <common:AsyncIcon HorizontalAlignment="Left" VerticalAlignment="Top" Margin="36,0,0,0"
                                  Width="225" Height="300" />
                <TextBlock Margin="36,310,0,0" Text="作者:" FontSize="18"
                               Width="300" Height="20"
                               HorizontalAlignment="Left" VerticalAlignment="Top"/>
                <TextBlock Margin="83,310,0,0" Text="{Binding Author}" FontSize="18"
                               Width="200" Height="20" TextWrapping="Wrap"
                               HorizontalAlignment="Left" VerticalAlignment="Top"/>

                <GridView x:Name="gridView"
                        Grid.Column="1" Margin="0,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Top"
                        SelectionMode="Multiple"
                        ItemsSource="{Binding Chapters}"
                        IsItemClickEnabled="True"
                        ItemClick="GridView_ItemClick">
                    <GridView.Template>
                        <ControlTemplate>
                            <Grid>
                                <ItemsPresenter />
                            </Grid>
                        </ControlTemplate>
                    </GridView.Template>
                    <GridView.ItemsPanel>
                        <ItemsPanelTemplate>
                            <WrapGrid />
                        </ItemsPanelTemplate>
                    </GridView.ItemsPanel>
                    <GridView.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Width="180">
                                <TextBlock FontSize="24" Text="{Binding ChapterTitle}" />
                            </StackPanel>
                        </DataTemplate>
                    </GridView.ItemTemplate>
                </GridView>
            </Grid>
        </ScrollViewer>

        <Grid Grid.Row="1" Height="160" Background="#99000000"
              Visibility="{Binding Loading}">
            <ProgressBar IsIndeterminate="True" />
        </Grid>

        <VisualStateManager.VisualStateGroups>

            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>

                <!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>

                <!-- The back button and title have different styles when snapped -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
    <Page.BottomAppBar>
        <AppBar>
            <StackPanel Orientation="Horizontal">
                <Button x:Name="btnHome" Style="{StaticResource HomeAppBarButtonStyle}"
                        AutomationProperties.Name="主页" Click="btnHome_Click" />
                <Button x:Name="btnFavorite" Style="{StaticResource FavoriteAppBarButtonStyle}"
                        AutomationProperties.Name="{Binding Tag, RelativeSource={RelativeSource Self}}" Click="btnFavorite_Click" Tag="添加收藏" />
                <Button x:Name="btnRefresh" Style="{StaticResource RefreshAppBarButtonStyle}"
                        AutomationProperties.Name="更新章节" Click="btnRefresh_Click"/>
                <Button x:Name="btnDownloadMode" 
                        Style="{StaticResource DownloadAppBarButtonStyle}" Tag="开启下载模式"
                        AutomationProperties.Name="{Binding Tag, RelativeSource={RelativeSource Self}}" Click="btnDownloadMode_Click"/>

                <Button x:Name="btnSelectAll" 
                        Style="{StaticResource SelectAllAppBarButtonStyle}" Tag="全选" 
                        AutomationProperties.Name="{Binding Tag, RelativeSource={RelativeSource Self}}" 
                        Click="btnSelectAll_Click" 
                        Visibility="{Binding DownloadMode}"/>
                <Button x:Name="btnDownload" Style="{StaticResource DownloadAppBarButtonStyle}"
                        AutomationProperties.Name="下载" Click="btnDownload_Click"
                        Visibility="{Binding DownloadMode}"/>
            </StackPanel>
        </AppBar>
    </Page.BottomAppBar>
</common:LayoutAwarePage>
